home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / VCal / Info.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.4 KB  |  199 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <malloc.h>
  19. #include "Info.h"
  20. #include "Entry.h"
  21. #include "Utils.h"
  22.  
  23. Info::Info()
  24. {
  25.   _size = 0;
  26.   _next = NULL;
  27. }
  28.  
  29. Info::~Info()
  30. {
  31. }
  32.  
  33. int
  34. Info::size()
  35. {
  36.   return _size;
  37. }
  38.  
  39. void
  40. Info::rewind()
  41. {
  42. // Redefine in subclass
  43. }
  44.  
  45. Entry *
  46. Info::nextEntry()
  47. {
  48. // Redefine in subclass
  49.   return NULL;
  50. }
  51.  
  52. /**********************************************************************/
  53.  
  54. MemoryInfo::MemoryInfo()
  55. {
  56.   entries = new Entry();
  57.   current = NULL;
  58.   _day = _month = _year = 0;
  59. }
  60.  
  61. MemoryInfo::~MemoryInfo()
  62. {
  63.   freeData();
  64. }
  65.  
  66. void
  67. MemoryInfo::rewind()
  68. {
  69.   current = entries->next();
  70. }
  71.  
  72. Entry *
  73. MemoryInfo::nextEntry()
  74. {
  75.   Entry *ptr;
  76.  
  77.   if (current) {
  78.     ptr = current;
  79.     current = current->next();
  80.     return ptr;
  81.   } else {
  82.     return NULL;
  83.   }
  84. }
  85.  
  86. int
  87. MemoryInfo::readDay(FILE *fd, int version)
  88. {
  89.   int each, num;
  90.   Entry *entry;
  91.  
  92.   if (!readInt(fd, &_day) ||
  93.       !readInt(fd, &_month) ||
  94.       !readInt(fd, &_year) ||
  95.       !readInt(fd, &num)) {
  96.     return 0;
  97.   } else {
  98.     for (each=0; each<num; each++) {
  99.       entry = new Entry();
  100.       entry->setDate(_day, _month, _year);
  101.       if (entry->readEntry(fd, version)) {
  102.     addEntry(entry);
  103.       } else {
  104.     delete entry;
  105.     return 0;
  106.       }
  107.     }
  108.     return 1;
  109.   }  
  110. }
  111.  
  112. void
  113. MemoryInfo::writeDay(FILE *fd, int annotate)
  114. {
  115.   Entry *entry;
  116.  
  117.   writeInt(fd, _day, annotate ? "Day" : NULL);
  118.   writeInt(fd, _month, annotate ? "Month" : NULL);
  119.   writeInt(fd, _year, annotate ? "Year" : NULL);
  120.   writeInt(fd, _size, annotate ? "Number of Slot Entries" : NULL);
  121.   entry = entries;
  122.   while (entry->next()) {
  123.     entry->next()->writeEntry(fd, annotate);
  124.     entry = entry->next();
  125.   }
  126. }
  127.  
  128. void
  129. MemoryInfo::addEntry(Entry *entry)
  130. {
  131.   Entry *ptr;
  132.  
  133.   ptr = entries;
  134.   while (ptr->next() &&
  135.      compareDates(ptr->next()->day(), ptr->next()->month(),
  136.               ptr->next()->year(),
  137.               entry->day(), entry->month(), entry->year()) <= 0) {
  138.     ptr = ptr->next();
  139.   }
  140.   entry->setNext(ptr->next());
  141.   ptr->setNext(entry);
  142.   _size++;
  143. }
  144.  
  145. int
  146. MemoryInfo::removeEntry(Entry *entry)
  147. {
  148.   Entry *ptr;
  149.  
  150.   ptr = entries;
  151.   while (ptr->next() && ptr->next() != entry) {
  152.     ptr = ptr->next();
  153.   }
  154.   if (ptr->next() == entry) {
  155.     ptr->setNext(entry->next());
  156.     _size--;
  157.     return 1;
  158.   } else {
  159.     return 0;
  160.   }
  161. }
  162.  
  163. void
  164. MemoryInfo::clear()
  165. {
  166.   freeData();
  167.   entries = new Entry();
  168.   current = NULL;
  169. }
  170.  
  171. void
  172. MemoryInfo::freeData()
  173. {
  174.   Entry *ptr;
  175.  
  176.   while (entries) {
  177.     ptr = entries;
  178.     entries = ptr->next();
  179.     delete ptr;
  180.   }
  181. }
  182.  
  183. int
  184. MemoryInfo::annotate()
  185. {
  186.   Entry *ptr;
  187.  
  188.   ptr = entries;
  189.   while (ptr->next()) {
  190.     if (ptr->next()->annotate()) {
  191.       return 1;
  192.     }
  193.     ptr = ptr->next();
  194.   }
  195.   return 0;
  196. }
  197.  
  198. /**********************************************************************/
  199.